stateDiagram-v2
	state "DealStatusNew" as 0
	state "DealStatusWaitForAcceptance" as 3
	state "DealStatusPaymentChannelCreating" as 4
	state "DealStatusPaymentChannelAddingFunds" as 5
	state "DealStatusAccepted" as 6
	state "DealStatusFailing" as 8
	state "DealStatusRejected" as 9
	state "DealStatusFundsNeeded" as 10
	state "DealStatusSendFunds" as 11
	state "DealStatusSendFundsLastPayment" as 12
	state "DealStatusOngoing" as 13
	state "DealStatusFundsNeededLastPayment" as 14
	state "DealStatusCompleted" as 15
	state "DealStatusDealNotFound" as 16
	state "DealStatusErrored" as 17
	state "DealStatusBlocksComplete" as 18
	state "DealStatusFinalizing" as 19
	state "DealStatusCheckComplete" as 21
	state "DealStatusCheckFunds" as 22
	state "DealStatusInsufficientFunds" as 23
	state "DealStatusPaymentChannelAllocatingLane" as 24
	state "DealStatusCancelling" as 25
	state "DealStatusCancelled" as 26
	state "DealStatusRetryLegacy" as 27
	state "DealStatusWaitForAcceptanceLegacy" as 28
	0 : On entry runs ProposeDeal
	4 : On entry runs WaitPaymentChannelReady
	5 : On entry runs WaitPaymentChannelReady
	6 : On entry runs SetupPaymentChannelStart
	8 : On entry runs CancelDeal
	10 : On entry runs ProcessPaymentRequested
	11 : On entry runs SendFunds
	12 : On entry runs SendFunds
	13 : On entry runs Ongoing
	14 : On entry runs ProcessPaymentRequested
	21 : On entry runs CheckComplete
	22 : On entry runs CheckFunds
	24 : On entry runs AllocateLane
	25 : On entry runs CancelDeal
	27 : On entry runs ProposeDeal
	[*] --> 0
	note right of 0
		The following events are not shown cause they can trigger from any state.

		ClientEventWriteDealProposalErrored - transitions state to DealStatusErrored
		ClientEventUnknownResponseReceived - transitions state to DealStatusFailing
		ClientEventDataTransferError - transitions state to DealStatusErrored
		ClientEventWriteDealPaymentErrored - transitions state to DealStatusErrored
		ClientEventProviderCancelled - transitions state to DealStatusCancelling
		ClientEventCancel - transitions state to DealStatusCancelling
	end note
	0 --> 0 : ClientEventOpen
	0 --> 3 : ClientEventDealProposed
	27 --> 28 : ClientEventDealProposed
	3 --> 27 : ClientEventDealRejected
	28 --> 9 : ClientEventDealRejected
	3 --> 16 : ClientEventDealNotFound
	28 --> 16 : ClientEventDealNotFound
	3 --> 6 : ClientEventDealAccepted
	28 --> 6 : ClientEventDealAccepted
	4 --> 8 : ClientEventPaymentChannelErrored
	5 --> 8 : ClientEventPaymentChannelErrored
	6 --> 8 : ClientEventPaymentChannelErrored
	6 --> 4 : ClientEventPaymentChannelCreateInitiated
	6 --> 24 : ClientEventPaymentChannelAddingFunds
	22 --> 5 : ClientEventPaymentChannelAddingFunds
	4 --> 24 : ClientEventPaymentChannelReady
	5 --> 13 : ClientEventPaymentChannelReady
	22 --> 13 : ClientEventPaymentChannelReady
	24 --> 8 : ClientEventAllocateLaneErrored
	24 --> 13 : ClientEventLaneAllocated
	10 --> 14 : ClientEventLastPaymentRequested
	13 --> 14 : ClientEventLastPaymentRequested
	14 --> 14 : ClientEventLastPaymentRequested
	18 --> 12 : ClientEventLastPaymentRequested
	10 --> 10 : ClientEventPaymentRequested
	13 --> 10 : ClientEventPaymentRequested
	18 --> 10 : ClientEventPaymentRequested
	3 --> 6 : ClientEventUnsealPaymentRequested
	28 --> 6 : ClientEventUnsealPaymentRequested
	13 --> 18 : ClientEventAllBlocksReceived
	14 --> 12 : ClientEventAllBlocksReceived
	18 --> 18 : ClientEventAllBlocksReceived
	10 --> 10 : ClientEventBlocksReceived
	13 --> 13 : ClientEventBlocksReceived
	14 --> 14 : ClientEventBlocksReceived
	10 --> 11 : ClientEventSendFunds
	14 --> 12 : ClientEventSendFunds
	22 --> 23 : ClientEventFundsExpended
	11 --> 8 : ClientEventBadPaymentRequested
	12 --> 8 : ClientEventBadPaymentRequested
	11 --> 8 : ClientEventCreateVoucherFailed
	12 --> 8 : ClientEventCreateVoucherFailed
	11 --> 22 : ClientEventVoucherShortfall
	12 --> 22 : ClientEventVoucherShortfall
	11 --> 13 : ClientEventPaymentSent
	12 --> 19 : ClientEventPaymentSent
	13 --> 21 : ClientEventComplete
	19 --> 15 : ClientEventComplete
	21 --> 15 : ClientEventCompleteVerified
	21 --> 17 : ClientEventEarlyTermination
	8 --> 17 : ClientEventCancelComplete
	25 --> 26 : ClientEventCancelComplete
	23 --> 22 : ClientEventRecheckFunds

	note left of 3 : The following events only record in this state.<br><br>ClientEventLastPaymentRequested<br>ClientEventPaymentRequested<br>ClientEventAllBlocksReceived<br>ClientEventBlocksReceived


	note left of 4 : The following events only record in this state.<br><br>ClientEventLastPaymentRequested<br>ClientEventPaymentRequested<br>ClientEventAllBlocksReceived<br>ClientEventBlocksReceived


	note left of 6 : The following events only record in this state.<br><br>ClientEventLastPaymentRequested<br>ClientEventPaymentRequested<br>ClientEventAllBlocksReceived<br>ClientEventBlocksReceived


	note left of 8 : The following events only record in this state.<br><br>ClientEventProviderCancelled


	note left of 10 : The following events only record in this state.<br><br>ClientEventAllBlocksReceived


	note left of 11 : The following events only record in this state.<br><br>ClientEventAllBlocksReceived


	note left of 24 : The following events only record in this state.<br><br>ClientEventLastPaymentRequested<br>ClientEventPaymentRequested<br>ClientEventAllBlocksReceived<br>ClientEventBlocksReceived


	note left of 25 : The following events only record in this state.<br><br>ClientEventProviderCancelled


	note left of 28 : The following events only record in this state.<br><br>ClientEventLastPaymentRequested<br>ClientEventPaymentRequested<br>ClientEventAllBlocksReceived<br>ClientEventBlocksReceived

